package com.example.myapplication.SuiPian;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.myapplication.R;
import com.example.myapplication.apter.Imglistmap;

import java.util.ArrayList;

public class ServlerFragment extends Fragment {

    private View view;
    private ViewPager rotationchart;
    private Context context;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_servler, container, false);
        initview();
        //轮播图
        imgmap();
        return view;
    }

    private void imgmap() {
        ArrayList<Integer> imglist = new ArrayList<>();
        imglist.add(R.drawable.fu_img);
        imglist.add(R.drawable.fu_imgmap1);
        imglist.add(R.drawable.fu_imgmap3);


        rotationchart.setAdapter(new Imglistmap(imglist,context));
        handler.sendEmptyMessageDelayed(0,3*1000);
    }

    private void initview() {
        rotationchart = view.findViewById(R.id.rotationchart);
        context = ServlerFragment.this.getContext();
    }


    Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(msg.what==0){
                int currentItem = rotationchart.getCurrentItem();
                currentItem = (currentItem+1)%3;
                rotationchart.setCurrentItem(currentItem);
                handler.sendEmptyMessageDelayed(0,3*1000);
            }
        }
    };



}